<?php

class staticActions extends ndeevorActions {

  public function executeHome(sfWebRequest $request) {
    
  }

  public function executeAbout(sfWebRequest $request) {
    $this->setTitle('About ndeevor');
  }

  public function executeServices(sfWebRequest $request) {
    $this->setTitle('Our Services');
  }

  public function executeContact(sfWebRequest $request) {
    require_once(sfConfig::get('sf_lib_dir') . '/recaptchalib.php');

    $this->form = new ContactUsForm();

    if ($request->isMethod('post')) {
      $formData = $request->getParameter(ContactUsForm::FORM_NAME);
      $this->form->bind($formData);

      if ($this->form->isValid()) {

        $phpMailer = new PHPMailer();
        //$phpMailer->Host = sfConfig::get('app_email_host');
        //$phpMailer->IsSMTP();
        //$phpMailer->SMTPAuth = true;
        //$phpMailer->Port = sfConfig::get('app_email_port');
        $phpMailer->Timeout = 60;
        $phpMailer->CharSet = 'UTF-8';
        //$phpMailer->Username = sfConfig::get('app_email_username');
        //$phpMailer->Password = sfConfig::get('app_email_password');
        
        $adminEmails = explode(',', sfConfig::get('app_admin_emails'));
        foreach ($adminEmails as $email) {
          $phpMailer->AddAddress(trim($email));
        }
        $phpMailer->From = 'info@ndeevor.com';
        $phpMailer->FromName = 'ndeevor';
        $phpMailer->AddReplyTo('no-reply@ndeevor.com');
        $phpMailer->Subject = 'ndeevor - Contact Us (' . $_SERVER['REMOTE_ADDR'] . ')';

        $message = 'Name: ' . $formData[ContactUsForm::FIELD_NAME] . "\n\n" .
                   'Email: ' . $formData[ContactUsForm::FIELD_EMAIL] . "\n\n";
        if ($formData[ContactUsForm::FIELD_PHONE]) {
          $message .= 'Phone: ' . $formData[ContactUsForm::FIELD_PHONE] . "\n\n";
        }
        $message .= 'Comments: ' . $formData[ContactUsForm::FIELD_COMMENTS] . "\n\n";
        if ($formData[ContactUsForm::FIELD_DESCRIPTION]) {
          $message .= 'Description: ' . $formData[ContactUsForm::FIELD_DESCRIPTION];
        }

        $phpMailer->Body = $message;
        $phpMailer->IsHTML(false);
        $phpMailer->Send();

        $this->redirect('@contact?success=1#aform');
      }
    }

    $this->setTitle('Contact Us');
  }

}